﻿<!DOCTYPE html>
<html lang="en">

    <head>

        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">

        <title>Kura's Hardware Shop</title>

        <!-- Bootstrap Core CSS -->
        <link href="css/bootstrap.min.css" rel="stylesheet">

        <!-- MetisMenu CSS -->
        <link href="css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="css/sb-admin-2.css" rel="stylesheet">

        <!-- Custom Fonts -->
        <link href="font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

        <!-- Bootstrap Core CSS -->
        <link href="css/bootstrap.min.css" rel="stylesheet">

        <!-- MetisMenu CSS -->
        <link href="css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">

        <!-- DataTables CSS -->
        <link href="css/plugins/dataTables.bootstrap.css" rel="stylesheet">

        <!-- Custom CSS -->
        <link href="css/sb-admin-2.css" rel="stylesheet">

        <!-- Custom Fonts -->
        <link href="font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
            <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <?php
        session_start();
        if (!isset($_SESSION['role'])) {
            header("Location: login.php");
        }
        include('script/categoriesScript.php');
        ?>
        <div id="wrapper">

            <!-- Navigation -->
            <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="index.html">Xin chào <?php echo $_SESSION['name'] ?></a> <!-- get User late -->
                </div>
                <!-- /.navbar-header -->

                <ul class="nav navbar-top-links navbar-right">

                    <li class="dropdown">
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            <i class="fa fa-user fa-fw"></i>  <i class="fa fa-caret-down"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="info.php"><i class="fa fa-user fa-fw"></i> Thông tin cá nhân</a>
                            </li>

                            <li class="divider"></li>
                            <li><a href="script/logoutScript.php"><i class="fa fa-sign-out fa-fw"></i> Ðang xuất</a>
                            </li>
                        </ul>
                        <!-- /.dropdown-user -->
                    </li>
                    <!-- /.dropdown -->
                </ul>
                <!-- /.navbar-top-links -->

                <div class="navbar-default sidebar" role="navigation">
                    <div class="sidebar-nav navbar-collapse">
                        <ul class="nav" id="side-menu">
                            <?php
                            if ($_SESSION['role'] == 1) {
                                ?>
                                <li>
                                    <a class="active" href="statistic.php"><i class="fa fa-bar-chart-o fa"></i> &nbspThống kê<span class="fa arrow"></span></a>
                                    <ul class="nav nav-second-level">
                                        <li>
                                            <a href="statistic.php">Doanh thu</a>
                                        </li>
                                    </ul>
                                </li>

                                <li>
                                    <a href="users.php"><i class="fa fa-user fa-fw"></i> Quản lí nhân viên</a>

                                    <!-- /.nav-second-level -->
                                </li>
                                <?php
                            }
                            ?>
                            <li>
                                <a href="customers.php"><i class="fa fa-wrench fa-fw"></i>&nbsp;Quản lí khách hàng</a>

                                <!-- /.nav-second-level -->
                            </li>
                            <li>
                                <a href="#"><i class="fa fa-shopping-cart fa-fw"></i> Quản lí sản phẩm<span class="fa arrow"></span></a>
                                <ul class="nav nav-second-level">
                                    <li>
                                        <a href="categories.php">Danh mục</a>
                                    </li>
                                    <li>
                                        <a href="manufacturers.php">Nhà sản xuất</a>
                                    </li>                                    
                                    <li>
                                        <a href="products.php">Sản phẩm</a>
                                    </li>
                                </ul>
                            </li>
                            <li>

                                <a href="#"><i class="fa fa-edit fa-fw"></i> Quản lí đơn hàng<span class="fa arrow"></span></a>
                                <ul class="nav nav-second-level">
                                    <li>
                                        <a href="orders_in.php">Hóa đơn nhập</a>
                                    </li>
                                    <li>
                                        <a href="orders_out.php">Hóa đơn xuất</a>
                                    </li>

                                </ul>
                            </li>
                        </ul>
                        <!-- /.nav-second-level -->
                    </div>
                    <!-- /.sidebar-collapse -->
                </div>
                <!-- /.navbar-static-side -->
            </nav>

            <div id="page-wrapper">
                <div class="row">
                    <?php
                    if (isset($_GET['status'])) {
                        if ($_GET['status'] == "updateSuccess") {
                            echo "<div class='alert alert-success' id='danger-alert'>
                                        Cập nhật thành công!
                                  </div>";
                        } else if ($_GET['status'] == "updateFailed") {
                            echo "<div class='alert alert-danger' id='danger-alert'>
                                        Lỗi không cập nhật được!
                                  </div>";
                        } else if ($_GET['status'] == "deleteSuccess") {
                            echo "<div class='alert alert-success' id='danger-alert'>
                                        Xóa danh mục thành công!
                                  </div>";
                        } else if ($_GET['status'] == "createSuccess") {
                            echo "<div class='alert alert-success' id='danger-alert'>
                                        Tạo danh mục thành công!
                                  </div>";
                        } else if ($_GET['status'] == "addManuSuccess") {
                            echo "<div class='alert alert-success' id='danger-alert'>
                                       Thêm nhà sản xuất thành công!
                                  </div>";
                        } else if ($_GET['status'] == "deleteManuSuccess") {
                            echo "<div class='alert alert-success' id='danger-alert'>
                                        Xóa nhà sản xuất khỏi danh mục thành công!
                                  </div>";
                        }
                    }
                    ?>
                </div>
                <div class="row">
                    <ul class="nav nav-tabs" role="tablist">
                        <li><a href="#new" role="tab" data-toggle="tab">Quản lý danh mục</a></li>
                        <li><a href="#abc" role="tab" data-toggle="tab">Cập nhật nhà sản xuất cho danh mục</a></li>
                        <li class="active"><a href="#list" role="tab" data-toggle="tab">Xem danh mục</a></li>
                    </ul>
                </div>
                <div class="row">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <!-- /.col-lg-12 -->
                            <div class="tab-content">  
                                <div id="new" class="tab-pane"> <!----------------------------- 1 tab -->
                                    <form method="POST" action="script/categoriesScript.php">
                                        <div class="form-group">
                                            <h3>Thêm mới danh mục</h3>
                                            <label>Tên</label>
                                            <input type="text" name="name" id="name" class="form-control">
                                        </div>         

                                        <div class="form-group">
                                            <label>Danh mục cha</label>
                                            <select id="danhMucCha" name="danhMucCha">
                                                <?php showCate() ?>
                                            </select>
                                        </div>

                                        <div class="modal-footer">
                                            <input class='btn btn-primary' type="submit" name="edit" value="Thêm danh mục">
                                        </div> 
                                    </form>

                                    <div class="form-group">
                                        <hr>
                                        <h3>Cập nhật danh mục</h3>
                                        <?php showTableDanhMuc(); ?>
                                    </div>

                                </div>

                                <div id="abc" class="tab-pane"> <!---------------------------------- 2 tab -->
                                    <form method="POST" action="script/categoriesScript.php">
                                        <div class="form-group">
                                            <label>Danh mục</label>                                            
                                            <select id="cate" name="cate" onchange="showUser(this.value)">
                                                <?php showCate() ?>
                                            </select>

                                        </div> 
                                        <div class="form-group">
                                            <label>Nhà sản xuất</label>
                                            <select id="manu" name="manu">
                                                <?php showManu() ?>
                                            </select>
                                        </div>
                                        <div class="modal-footer">
                                            <input class='btn btn-primary' type="submit" name="edit" value="Thêm nhà sản xuất">
                                            <input class='btn btn-primary' type="submit" name="edit" value="Xóa nhà sản xuất">
                                        </div>    
                                    </form>
                                </div>

                                <div id="list" class="tab-pane active"> <!---------------------------------- tab 3-->
                                    <form method="POST" action="script/categoriesScript.php"  >
                                        <div class="form-group col-lg-6">
                                            <label>Danh mục</label>                                           
                                            <select id="cate1" name="cate1"  >
                                                <?php showCate() ?>
                                            </select>                                     
                                        </div> 
                                        <div class="form-group col-lg-6">
                                            <label>Danh mục cha</label>
                                            <input  type="text" name="name1" id="name1" class="form-control" readonly="true">
                                        </div>
                                        <div id="divProManu">

                                        </div>   

                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <hr>
        </div>
        <!-- /b?ng c?p nh?t -->

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                        <h4 class="modal-title" id="myModalLabel">Cập nhật</h4>
                    </div>
                    <div class="modal-body">
                        <form method="POST" action="script/categoriesScript.php">
                            <div class="form-group">
                                <label>Tên cũ</label>
                                <input type="text" name="tenCu" id="tenCu" class="form-control" readonly="true">
                            </div>
                            <div class="form-group">
                                <label>Tên mới</label>
                                <input type="text" name="tenMoi" id="tenMoi" class="form-control">
                            </div>
                            <div class="form-group">
                                <label>Danh mục cha</label>                                           
                                <select id="cateCha2" name="cateCha2"  >
                                    <?php showCate() ?>
                                </select>                                     
                            </div> 
                            <div class="modal-footer">
                                <input class='btn btn-primary' type="submit" name="edit" value="Cập nhật">
                                <input class='btn btn-primary' type="submit" name="edit" value="Xóa">
                            </div>
                        </form>
                    </div>                    
                </div>
            </div>
        </div>    

        <!-- jQuery Version 1.11.0 -->
        <script src="js/jquery-1.11.0.js"></script>

        <!-- Bootstrap Core JavaScript -->
        <script src="js/bootstrap.min.js"></script>

        <!-- Metis Menu Plugin JavaScript -->
        <script src="js/plugins/metisMenu/metisMenu.min.js"></script>

        <!-- Custom Theme JavaScript -->
        <script src="js/sb-admin-2.js"></script>

        <!-- DataTables JavaScript -->
        <script src="js/plugins/dataTables/jquery.dataTables.js"></script>
        <script src="js/plugins/dataTables/dataTables.bootstrap.js"></script>

        <!-- Custom Theme JavaScript -->
        <script src="js/sb-admin-2.js"></script>

        <script>
                                                $(document).ready(function() {
                                                    $('#dataTables-example').dataTable();

                                                });
        </script>
        <script>
            function view(e) {
                //alert(e.id);
                var table = document.getElementById("dataTables-example");
                var numRows = table.rows.length;
                var manu = table.rows[e.id].cells[1].innerText;
                var cate = table.rows[e.id].cells[0].innerText;
                //alert(manu);
                var inputCate = document.getElementById("cate-va");
                inputCate.value = cate;
                var inputManu = document.getElementById("manu-va");
                inputManu.value = manu;
            }
        </script>
        <script>
            $("#cate1")
                    .change(function() {
                        var str = "";
                        $("#cate1 option:selected").each(function() {
                            str += $(this).text() + " ";
                        });
                        var cate = $("#cate1").val();

                        $.ajax({
                            type: "POST",
                            url: "./script/categoriesScript.php",
                            data: {
                                cateToManu: str,
                                type: "1"
                            }
                        })
                                .done(function(msg) {
                                    //        alert(msg);
                                    $('#divProManu').html(msg);
                                });

                        $.ajax({
                            type: "POST",
                            url: "./script/categoriesScript.php",
                            data: {
                                parentCate: cate

                            }
                        })
                                .done(function(msg) {
                                    //
                                    //  alert(msg);
                                    $('#name1').val(msg);
                                });



                    })
                    .change();
        </script>

        <script>
            $("button").click(function() {
                if ($(this).attr("value") == "edit") {
                    var gName = $(this).closest('tr').find('td:eq(0)').text();
                    $('#tenCu').val(gName);
                }
            });
        </script>
        <script>
            $("#danger-alert").fadeTo(2000, 500).slideUp(500, function() {
                $("#danger-alert").alert('close');
            });
        </script>
    </body>

</html>
